<template>
    <a-card title="天线控制">
        <a-button slot="extra" type='primary' style="margin-right: 10px;" @click="resetForm">重置</a-button>
        <a-button slot="extra" type='primary' @click="sendConfig">设置</a-button>
        <a-form-model :model="formAntenna" ref="ruleForm" :rules="rules" :label-col="labelCol"
            :wrapper-col="wrapperCol">
            <a-row>
                <a-col :span=12>
                    <a-form-model-item label="卫星编号">
                        <a-input style="width:100%" v-model="formAntenna.ID"></a-input>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="卫星经度">
                        <a-input-number style="width:100%" v-model="formAntenna.Longi"></a-input-number>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="信标频率(MHz)">
                        <a-input-number style="width:100%" v-model="formAntenna.Freq"></a-input-number>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="极化方式">
                        <!-- <a-input style="width:100%" v-model="formAntenna.attenuator"></a-input> -->
                        <a-select style="width: 100%" v-model="formAntenna.Pol">
                            <a-select-option value="2">
                                左旋
                            </a-select-option>
                            <a-select-option value="3">
                                右旋
                            </a-select-option>

                        </a-select>
                    </a-form-model-item>
                </a-col>

            </a-row>
            <a-row v-if="!flagDisable">
                <a-col :span=12>
                    <a-form-model-item label="速度">
                        <a-input read-only style="width:100%" v-model="formAntenna.speedAzimuth"></a-input>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="方位/俯仰(速度)">
                        <!-- <a-input read-only style="width:100%" v-model="formAntenna.speedPitch"></a-input> -->
                        <j-dict-select-tag disabled type="list" v-model="formAntenna.speedPitch"
                            dictCode="azimuth_pitch" placeholder="请选择" />
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="位置">
                        <a-input read-only style="width:100%" v-model="formAntenna.positionAndOrientation"></a-input>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="方位/俯仰(位置)">
                        <!-- <a-input read-only style="width:100%" v-model="formAntenna.positionPitch"></a-input> -->
                        <j-dict-select-tag disabled type="list" v-model="formAntenna.positionPitch"
                            dictCode="azimuth_pitch" placeholder="请选择" />
                    </a-form-model-item>
                </a-col>
            </a-row>
            <a-row v-else>
                <a-col :span=12>
                    <a-form-model-item label="速度">
                        <a-input style="width:100%" v-model="formAntenna.speedAzimuth"></a-input>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="方位/俯仰(速度)">
                        <!-- <a-input style="width:100%" v-model="formAntenna.speedPitch"></a-input> -->
                        <j-dict-select-tag type="list" v-model="formAntenna.speedPitch" dictCode="azimuth_pitch"
                            placeholder="请选择" />
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="位置">
                        <a-input style="width:100%" v-model="formAntenna.positionAndOrientation"></a-input>
                    </a-form-model-item>
                </a-col>
                <a-col :span=12>
                    <a-form-model-item label="方位/俯仰(位置)">
                        <!-- <a-input style="width:100%" v-model="formAntenna.positionPitch"></a-input> -->

                        <j-dict-select-tag type="list" v-model="formAntenna.positionPitch" dictCode="azimuth_pitch"
                            placeholder="请选择" />
                    </a-form-model-item>
                </a-col>
            </a-row>
            <a-row>

                <a-col :span=12>
                    <a-form-model-item label="工作模式" prop="Mode">
                        <j-dict-select-tag type="list" v-model="formAntenna.Mode" dictCode="antenna_working_mode"
                            placeholder="请选择" @change="handleChangeMode" />
                    </a-form-model-item>
                </a-col>

            </a-row>
            <!-- <a-card title="速度控制设置">
                    <a-row>
                        <a-col :span=12>
                            <a-form-model-item label="方位">
                                <a-input style="width:100%" v-model="formAntenna.attenuator"></a-input>
                            </a-form-model-item>
                        </a-col>
                        <a-col :span=12>
                            <a-form-model-item label="俯仰">
                                <a-input style="width:100%" v-model="formAntenna.attenuator"></a-input>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </a-card>
                <a-card title="位置控制设置">
                    <a-row>
                        <a-col :span=12>
                            <a-form-model-item label="方位">
                                <a-input style="width:100%" v-model="formAntenna.attenuator"></a-input>
                            </a-form-model-item>
                        </a-col>
                        <a-col :span=12>
                            <a-form-model-item label="俯仰">
                                <a-input style="width:100%" v-model="formAntenna.attenuator"></a-input>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </a-card> -->

        </a-form-model>
    </a-card>


</template>

<script>
import { httpAction } from '../../../api/manage';

export default {
    data() {
        return {
            rules: {
                Mode: [{ required: true, message: '请选择', trigger: 'change,blur' },],

            },
            formAntenna: {},
            labelCol: { span: 9 },
            wrapperCol: { span: 14 },
            url: {
                sendDevicePackage: '/device/nmcDeviceGridValue/sendDevicePackage'
            },
            flagDisable: false,
        }
    },
    methods: {
        resetForm() {
            this.formAntenna = {}
            this.$refs.ruleForm.resetFields();
        },
        handleChangeMode(val) {
            if (Number(val) == 7) {
                this.flagDisable = true
                // this.$forceUpdate()
            } else {
                this.flagDisable = false
            }
        },
        setSatellite() {
            let data = {
                "channelCode": "天线",
                "gridValues": [
                    {
                        "gridCode": "133-天线-设置卫星参数-卫星编号",
                        "gridValue": this.formAntenna.ID
                    },
                    {
                        "gridCode": "133-天线-设置卫星参数-卫星经度",
                        "gridValue": this.formAntenna.Longi * 100
                    },
                    {
                        "gridCode": "133-天线-设置卫星参数-信标频率",
                        "gridValue": this.formAntenna.Freq * 1000
                    },
                    {
                        "gridCode": "133-天线-设置卫星参数-极化方式",
                        "gridValue": this.formAntenna.Pol
                    },
                ],
                "packageCode": "133-天线-设置卫星参数"
            }
            httpAction(this.url.sendDevicePackage, data, 'post').then(res => {
                if (res.success) {
                    this.$message.success(res.message)
                } else {
                    this.$message.error(res.message)
                }
            })
        },
        setPosition() {
            let temp = {

                "channelCode": "天线",
                "gridValues": [
                    {
                        "gridCode": "139-通道",
                        "gridValue": this.formAntenna.positionPitch
                    },
                    {
                        "gridCode": "139-位置",
                        "gridValue": this.formAntenna.positionAndOrientation * 100
                    },
                ],
                "packageCode": "139-天线-手动位置控制"
            }

            httpAction(this.url.sendDevicePackage, temp, 'post').then(res => {
                if (res.success) {
                    this.$message.success(res.message)
                } else {
                    this.$message.error(res.message)
                }
            })
        },
        setSpeed() {
            let temp = {

                "channelCode": "天线",
                "gridValues": [
                    {
                        "gridCode": "137-通道",
                        "gridValue": this.formAntenna.speedAzimuth
                    },
                    {
                        "gridCode": "137-速度",
                        "gridValue": this.formAntenna.speedPitch * 100
                    },
                ],
                "packageCode": "137-天线-手动速度控制"
            }

            httpAction(this.url.sendDevicePackage, temp, 'post').then(res => {
                if (res.success) {
                    this.$message.success(res.message)
                } else {
                    this.$message.error(res.message)
                }
            })
        },
        sendConfig() {
            let temp = {

                "channelCode": "天线",
                "gridValues": [
                    {
                        "gridCode": "135-工作模式",
                        "gridValue": this.formAntenna.Mode
                    },
                ],
                "packageCode": "135-天线-设置工作模式"
            }

            httpAction(this.url.sendDevicePackage, temp, 'post').then(res => {
                if (res.success) {
                    this.$message.success(res.message)
                    if (this.flagDisable) {
                        this.setSpeed()
                        this.setPosition()
                    }
                    this.setSatellite()
                } else {
                    this.$message.error(res.message)
                }
            })

        },
    }
}
</script>

<style scoped>
.ant-card-bordered {
    height: 100%;
}
</style>